package logic

import (
	"context"
	"person/models/mysql"

	"person/perrpc/internal/svc"
	"person/perrpc/perrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserDetailsLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserDetailsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserDetailsLogic {
	return &UserDetailsLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserDetailsLogic) UserDetails(in *perrpc.UserDetailsRequest) (*perrpc.UserDetailsResponse, error) {
	// todo: add your logic here and delete this line
	var user mysql.User

	if err := user.DetailsUser(mysql.DB, in.UserId); err != nil {
		return nil, err
	}
	return &perrpc.UserDetailsResponse{
		UserId:   int64(user.ID),
		Account:  user.Account,
		Password: user.Password,
	}, nil
}
